﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hsp.WebNovels.App.Utility
{
    /// <summary>
    /// SqlSugar基类
    /// </summary>
    public class SqlSugarBase
    {
        /// <summary>
        /// 数据库连接串
        /// </summary>
        public static string? Db_ConnectionString { get; set; }

        /// <summary>
        /// SqlSugar
        /// </summary>
        public static SqlSugarClient Db
        {
            get => new(new ConnectionConfig()
            {
                ConnectionString = Db_ConnectionString,
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                ConfigId = "0"
            });
        }

        /// <summary>
        /// ClientInstance
        /// </summary>
        /// <returns></returns>
        public static SqlSugarClient GetClientInstance()
        {
            return new(new ConnectionConfig()
            {
                ConnectionString = Db_ConnectionString,
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                ConfigId = "0"
            });
        }

        /// <summary>
        /// SqlSugar(单例)
        /// </summary>
        public static SqlSugarScope Scope
        {
            get => new(new ConnectionConfig()
            {
                ConnectionString = Db_ConnectionString,
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                ConfigId = "0"
            });
        }

        /// <summary>
        /// SqlSugarScope
        /// </summary>
        /// <returns></returns>
        public static SqlSugarScope GetScopeInstance()
        {
            return new(new ConnectionConfig()
            {
                ConnectionString = Db_ConnectionString,
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                ConfigId = "0"
            });
        }

    }
}
